﻿package mortal.game.view.copy.guildDefenseCopy.panel
{
    import Message.Public.*;
    import com.gengine.utils.*;
    import com.mui.controls.*;
    import com.mui.display.*;
    import com.mui.utils.*;
    import extend.language.*;
    import fl.data.*;
    import mortal.common.global.*;
    import mortal.component.gconst.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.info.*;
    import mortal.game.resource.tableConfig.*;
    import mortal.game.scene3D.map3D.util.*;
    import mortal.game.view.common.*;
    import mortal.game.view.copy.*;
    import mortal.game.view.mainUI.smallMap.view.*;
    import mortal.game.view.mainUI.smallMap.view.data.*;

    public class GuildDefenseMiniMap extends CopyInfoPanelBase
    {
        private var _bgSprite:GSprite;
        private var _bgImg:GImageBitmap;
        private var _leftTime:SecTimerView;
        private var _lineBg:ScaleBitmap;
        private var _smallMap:SmallMapEmbedView;
        private var _txtBlood:GTextFiled;
        private var _curLv:GTextFiled;
        private var _curNum:GTextFiled;
        private var _HPProgressBar:BaseProgressBar;
        private var _towerList:GTileList;
        private var _data:Array;
        private const copyTime:int = 900;

        public function GuildDefenseMiniMap()
        {
            super(ImagesConst.copyInfoPanelTitle_GuildDefenseCopy, 251, 542);
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._bgSprite = UICompomentPool.getUICompoment(GSprite);
            this._bgSprite.mouseEnabled = false;
            this._bgSprite.mouseChildren = false;
            _bodySprite.addChild(this._bgSprite);
            this._bgImg = UIFactory.gImageBitmap(ImagesConst.GuildDefenceMiniBg, 0, 0, this._bgSprite);
            this._curLv = UIFactory.textField("", 22 + 11, -9 + 22, 198, 20, _bodySprite, GlobalStyle.textFormatHuang2);
            this._leftTime = UIFactory.secTimeView(Language.getString(35253), 88 + 11, -9 + 22, 120, 22, _bodySprite, GlobalStyle.textFormatHuang2.right());
            this._leftTime.timeOutHandler = this.timeCompl;
            this._smallMap = UIFactory.smallMapEmbedView(this.getSmallBgUrl(), 0 + 11, 55 + 22, _bodySprite, true);
            this._smallMap.run();
            this._lineBg = UIFactory.bg(0 + 11, 20 + 22, 228, 24, _bodySprite, ImagesConst.RegionTitleBg);
            pushUIToDisposeVec(UIFactory.textField(Language.getString(35254), 163 + 11, 18 + 22, 80, 22, _bodySprite, GlobalStyle.textFormatHuang2));
            pushUIToDisposeVec(UIFactory.textField(Language.getString(35255), 3 + 11, 228 + 22, 80, 22, _bodySprite, GlobalStyle.textFormatHuang2));
            pushUIToDisposeVec(UIFactory.gBitmap(ImagesConst.BossDrop_7, 135 + 11, 230 + 22, _bodySprite));
            this._txtBlood = UIFactory.gTextField("", 3 + 11, 18 + 22, 67, 22, _bodySprite);
            this._txtBlood.htmlText = HTMLUtil.addColor(Language.getString(35256), GlobalStyle.colorHuang2);
            this._curNum = UIFactory.gTextField("", 10 + 11, 228 + 22, 120, 22, _bodySprite, GlobalStyle.textFormatDanLan.right());
            var _loc_1:* = BossConfig.instance.getInfoByCode(GameConst.DefenseCopyGoldStuffCode);
            this._HPProgressBar = UIFactory.getUICompoment(BaseProgressBar, 56 + 11, 21 + 22, _bodySprite);
            this._HPProgressBar.setBg(ImagesConst.PetLifeBg, true, 107, 15);
            this._HPProgressBar.setProgress(ImagesConst.GuildWarSelfProgress, true, 2, 2, 104, 12);
            this._HPProgressBar.setLabel(BaseProgressBar.ProgressBarTextNumber, -43, -3);
            this._HPProgressBar.mouseChildren = false;
            this._HPProgressBar.mouseEnabled = true;
            this._HPProgressBar.setValue(0, GameConst.GuildDefenseBlood);
            this._towerList = UIFactory.tileList(10 + 11, 265 + 22, 225, 245, _bodySprite);
            this._towerList.columnWidth = 225;
            this._towerList.rowHeight = 60;
            this._towerList.horizontalGap = 0;
            this._towerList.setStyle("cellRenderer", GuildDefenseTowerRender);
            this._towerList.selectable = false;
            pushUIToDisposeVec(UIFactory.bg(0 + 11, 321 + 22, 225, 1, _bodySprite, ImagesConst.SplitLine6));
            pushUIToDisposeVec(UIFactory.bg(0 + 11, 382 + 22, 225, 1, _bodySprite, ImagesConst.SplitLine6));
            pushUIToDisposeVec(UIFactory.bg(0 + 11, 442 + 22, 225, 1, _bodySprite, ImagesConst.SplitLine6));
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            this._bgSprite.dispose(param1);
            this._bgSprite = null;
            this._bgImg.dispose(param1);
            this._bgImg = null;
            this._curNum.dispose(param1);
            this._curNum = null;
            this._leftTime.dispose(param1);
            this._leftTime = null;
            this._lineBg.dispose(param1);
            this._lineBg = null;
            this._smallMap.dispose(param1);
            this._smallMap = null;
            this._txtBlood.dispose(param1);
            this._txtBlood = null;
            this._HPProgressBar.dispose(param1);
            this._HPProgressBar = null;
            this._curLv.dispose(param1);
            this._curLv = null;
            this._towerList.dispose(param1);
            this._towerList = null;
            if (this._data)
            {
                this._data.length = 0;
                this._data = null;
            }
            MsgManager.removeTaskTarget();
            super.disposeImpl(param1);
            return;
        }// end function

        private function getCopyDataProvider() : DataProvider
        {
            var _loc_2:Object = null;
            var _loc_1:* = new DataProvider();
            var _loc_3:* = Cache.instance.copy.guildDefence.guildUpdateInfo;
            var _loc_4:int = 1;
            while (_loc_4 <= 4)
            {
                
                _loc_2 = {index:_loc_4, info:_loc_3.towers[_loc_4], IconData:this._data[(_loc_4 - 1)], totalNum:int(this._curNum.text)};
                _loc_1.addItem(_loc_2);
                _loc_4++;
            }
            return _loc_1;
        }// end function

        private function getSmallBgUrl() : String
        {
            var _loc_1:* = ImagesConst.GuildDefenseMiniMap;
            return _loc_1;
        }// end function

        private function timeCompl() : void
        {
            this._leftTime.stop();
            return;
        }// end function

        private function onSecViewTimeChangeHandler(event:DataEvent) : void
        {
            var _loc_2:* = event.data as int;
            if (this.copyTime - _loc_2 > 60)
            {
                MsgManager.showTaskTarget(Language.getString(35257), 5);
                this._leftTime.removeEventListener(EventName.SecViewTimeChange, this.onSecViewTimeChangeHandler);
            }
            else
            {
                MsgManager.showTaskTarget(Language.getStringByParam(35258, 60 - this.copyTime + _loc_2));
            }
            return;
        }// end function

        public function updateAll(param1:SGuildDefenseInfo) : void
        {
            if (this._data == null)
            {
                this._data = Cache.instance.smallmap.getDataByType(SmallMapShowType.MapShowTypeBoss, MapFileUtil.mapID);
                this._smallMap.showBoosPoint(SmallMapShowType.MapShowTypeBoss, 227 / 6800, this._data);
            }
            param1 = Cache.instance.copy.guildDefence.guildUpdateInfo;
            if (param1)
            {
                if (!this._leftTime.running)
                {
                    if (this.copyTime - param1.surplusSeconds < 60)
                    {
                        this._leftTime.configEventListener(EventName.SecViewTimeChange, this.onSecViewTimeChangeHandler);
                    }
                    this._leftTime.setLeftTime(param1.surplusSeconds);
                }
                this._curLv.text = Language.getStringByParam(35259, param1.waves);
                this._HPProgressBar.value = param1.blood;
                this._towerList.dataProvider = this.getCopyDataProvider();
                this._curNum.text = param1.myTowerPiece.toString();
            }
            return;
        }// end function

    }
}
